﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Findr
{
    public partial class ctlMain : UserControl
    {
        public ctlMain(ref Communicator comm)
        {
            InitializeComponent();
            comm.ContactUpdate += UpdateContactsHandler;
        }

        private void UpdateContactsHandler(FindrServer.Contact[] contacts)
        {
            tbContacts.Invoke(new EventHandler(delegate(object o, EventArgs a)
                {
                    tbContacts.Text = "";
                    foreach (FindrServer.Contact contact in contacts)
                    {
                        tbContacts.Text += contact.name + " -> " + contact.latitude + 
                            ", " + contact.longitude + "\r\n";
                    }
                    lbLastUpdated.Text = DateTime.Now.ToLongTimeString();
                    lbOnlineFriends.Text = contacts.Length.ToString() + " online friends";
                }));
        }
    }
}
